<?php

use Webman\Route;

$plugin = get_plugin_name(__FILE__);

Route::group('/app/'.$plugin, function () use ($plugin) {
    Route::any('/', function ()use($plugin){
        return redirect('/app/'.$plugin.'/'.config('plugin.'.$plugin.'.app.default_app'));
    });

    //公众号消息与事件接收配置
    Route::any('/appid/{appid}', function ($request, $appid)use($plugin){
        $uri_arr = explode('?', $request->uri());
        $other = isset($uri_arr[1]) ? $uri_arr[1] : '';
        return redirect('/app/'.$plugin.'/platform/api?appid=' . $appid . '&' . $other);
    });

    //bot消息与事件接收配置
    Route::any('/bot/{driver}', [
        \plugin\wechat\app\bot\controller\Api::class, 'index'
    ]);
});

Route::fallback(function ($request) use ($plugin) {
    if ($request->expectsJson()) {
        return json(['code' => 404, 'msg' => '404 not found']);
    }
    return view(config('plugin.'.$plugin.'.app.404_tpl'), []);
});